/**
* Copyright @ 2023 iAuto (Shanghai) Co., Ltd.
* All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are NOT permitted except as agreed by
* iAuto (Shanghai) Co., Ltd.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*/



import {
  BaseApiResponse,
  CartypeResultItem,
  ChangeList,
  SoaDetailParams,
  SoaDetailResult,
  SoaListParams,
  SoaListResult,
  // SocPublish,
  ApprovalParams,
  userPermissionListParams,
  docPermissionListParams,
  republishParams,
  getUserPermissionDetailParams
} from '@/types/soaSocType';
import { Methods } from '@/types/soaSocType';
import request from '../utils/request';
// import type { userSoaPermissionListApiParams } from '@/types/userSoaPermissionCheck';

// 服务列表
export async function getSoaList(payload: SoaListParams) {
  return request<BaseApiResponse<SoaListResult>>(`/api/ms-soa-service/v1/admin/service/list`, {
    // return request<BaseApiResponse<any>>(`/api/ms-soa-service/v1/admin/service/list`, {
    method: Methods.GET,
    params: payload,
  });
}
// 服务导入记录列表
export async function getStatusRecordList(payload: SoaListParams) {
  return request<BaseApiResponse<SoaListResult>>(`/api/ms-soa-service/v1/admin/carmodel/soc/statusRecordList`, {
    // return request<BaseApiResponse<SoaListResult>>(`/api/servicemgmt/v1/admin/carmodel/soc/statusRecordList`, {
    method: Methods.GET,
    params: payload,
  });
}

// 服务详情
export async function getSoaDetail(payload: SoaDetailParams) {
  return request<BaseApiResponse<SoaDetailResult>>(`/api/ms-soa-service/v1/admin/service/detail`, {
    method: Methods.GET,
    params: payload,
  });
}
// 获取未发布的服务的车型车系
export async function getPublishDetail() {
  return request<BaseApiResponse<CartypeResultItem>>(`/api/ms-soa-service/v1/admin/service/publish/detail`,
    {
      method: Methods.GET,
    }
  );
}
// 清空车型车系版本服务
export async function postSocReback(payload: any) {
  return request<BaseApiResponse>(`/api/ms-soa-service/v1/admin/service/back`, {
    method: Methods.POST,
    data: payload,
  });
}
// 清空车型车系版本服务
export async function postSocDel(payload: any) {
  return request<BaseApiResponse>(`/api/ms-soa-service/v1/admin/carmodel/soc/del`, {
    method: Methods.POST,
    data: payload,
  });
}
// 导入excel
export async function importExcel(payload: FormData) {
  return request<BaseApiResponse>(`/api/ms-soa-service/v1/admin/service/importExcel`, {
    method: Methods.POST,
    data: payload,
    requestType: 'form',
    timeout: undefined
  });
}
// 已发布服务下架
export async function serviceOffline(payload: any) {
  return request<BaseApiResponse>(`/api/ms-soa-service/v1/admin/service/offline`, {
    method: Methods.POST,
    data: payload,
  });
}
// 发布某个车型的某个SOC版本
export async function socpublish(payload: any) {
  return request<BaseApiResponse>(`/api/ms-soa-service/v1/admin/carmodel/soc/publish`, {
    method: Methods.POST,
    data: payload,
  });
}
// 获取某个车型某个SOC版本下发生变更的接口
export async function changeList(payload: ChangeList) {
  return request<BaseApiResponse>(`/api/ms-soa-service/v1/admin/carmodel/soc/change/list`, {
    method: Methods.GET,
    params: payload,
  });
}
// 导出excel
export async function exportExcel(payload: ChangeList) {
  return request<BaseApiResponse>(`/api/ms-soa-service/v1/admin/carmodel/soc/exportExcel`, {
    method: Methods.GET,
    params: payload,
  });
}
// 导入检测
export async function importExcelCheck(payload: ChangeList) {
  return request<BaseApiResponse>(`/api/ms-soa-service/v1/admin/service/importExcelCheck`, {
    method: Methods.POST,
    data: payload,
    requestType: 'form',
    timeout: undefined
  });
}
// 用户权限管理
export async function getUserPermissionList(payload: userPermissionListParams) {
  return request<BaseApiResponse>(`/auth-ms/v1/admin/user/_list`, {
    method: Methods.GET,
    params: payload,
  });
}


//权限列表获取
export async function soaPermissionList(payload: ChangeList) {
  return request<BaseApiResponse>(`/api/ms-soa-service/v1/admin/user/permission/baseList`, {
    method: Methods.GET,
    params: payload,
  });
}
// 获取用户的api权限申请列表 
export async function getUserPermissionDetail(payload: getUserPermissionDetailParams) {
  return request<BaseApiResponse>(`/api/ms-soa-service/v1/admin/user/permission/detail`, {
    method: Methods.GET,
    params: payload,
  });
}


//权限审核审批
export async function permissionCheck(payload: ChangeList) {
  return request<BaseApiResponse>(`/api/ms-soa-service/v1/admin/user/permission/batchApproval`, {
    method: Methods.POST,
    data: payload,
  });
}

// 获取车型车系下最新发布的列表
export async function permissionServiceList(payload: docPermissionListParams) {
  return request<BaseApiResponse>(`/api/ms-soa-service/v1/admin/user/permission/serviceList`, {
    method: Methods.GET,
    params: payload,
  });
}
// 再次发布服务
export async function republish(payload: republishParams) {
  return request<BaseApiResponse>(`/api/ms-soa-service/v1/admin/carmodel/soc/republish`, {
    method: Methods.POST,
    data: payload,
  });
}
// 取消授权
export async function approval(payload: ApprovalParams) {
  return request<BaseApiResponse>(`/api/ms-soa-service/v1/admin/user/permission/approval`, {
    method: Methods.POST,
    data: payload,
  });
}